'''
Created on 14.11.2012

@author: felix_000
'''
from game.player.PlayerInterface import PlayerInterface
from game.player.alpha_beta_player.alpha_beta_framework.alphabeta import NegaMax
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.CenterHeuristic import CenterHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.DepthHeuristic import DepthHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.GroupHeuristic import GroupHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.WinningHeuristic import WinningHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.CompleteFieldGroupHeuristic import CompleteFieldGroupHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.OpenDirectionsHeuristic import OpenDirectionsHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.CountStonesHeuristic import CountStonesHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.CompleteFieldHeuristic import CompleteFieldHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.movefilter.NoEmptySpaceMovesFilter import NoEmptySpaceMovesFilter
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.RandomHeuristic import RandomHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.MaxLenHeuristic import MaxLenHeuristic
from game.player.alpha_beta_player.alpha_beta_framework.heuristic.FourWithFreedom import FourWithFreedom

class AlphaBetaPlayer(PlayerInterface):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        '''
        completeFieldHeuristic = CompleteFieldHeuristic(1)
        completeFieldHeuristic.addHeuristic(CompleteFieldGroupHeuristic(5))
        completeFieldHeuristic.addHeuristic(OpenDirectionsHeuristic(2))
        completeFieldHeuristic.addHeuristic(CountStonesHeuristic(10))
        #heuristicFeatures = [completeFieldHeuristic, WinningHeuristic(1000000), CenterHeuristic(10), GroupHeuristic(10), DepthHeuristic(1000)]
        heuristicFeatures = [WinningHeuristic(100000000), CenterHeuristic(10), DepthHeuristic(1000), RandomHeuristic(1,0,5), MaxLenHeuristic(20), FourWithFreedom(100), GroupHeuristic(100), CountStonesHeuristic(1000)]
        moveFilter = NoEmptySpaceMovesFilter()
        self.alphaBeta = NegaMax(heuristicFeatures, moveFilter, 5)
    
    def isHumanPlayer(self):
        return False
    
    def stopable(self):
        return True
    
    def setStopEvent(self, stopEvent):
        self.stopEvent = stopEvent
    
    def requestAction(self, field, color, switchAllowed, ply):
        return self.alphaBeta.search(field, color, switchAllowed, ply, self.stopEvent)

